#!/bin/bash

# 检查是否存在任何 DHCP 相关包（dhcp、isc-dhcp-server、dhcp3-server）
dhcp_pkgs=$( (rpm -qa 2>/dev/null | grep -E '^dhcp') ; (dpkg -l 2>/dev/null | grep -E '^ii.*(dhcp|isc-dhcp-server|dhcp3-server)') )

if [ -n "$dhcp_pkgs" ]; then
    echo "[-] 检测失败: 检测到已安装的 DHCP 相关包"
    echo "    已安装的 DHCP 包如下:"
    echo "$dhcp_pkgs" | sed 's/^/    /'
    
    # 检查 dhcpd 服务状态
    if systemctl is-active dhcpd >/dev/null 2>&1; then
        echo "    dhcpd 服务正在运行"
    fi
    if systemctl is-enabled dhcpd >/dev/null 2>&1; then
        echo "    dhcpd 服务已启用"
    fi

    exit 1
else
    echo "[+] 检测通过: 未检测到任何 DHCP 服务器相关包"
    exit 0
fi
